/**
 * @file exercise_record.h
 *
 */

#ifndef EXERCISE_RECORD_H
#define EXERCISE_RECORD_H

#ifdef __cplusplus
extern "C" {
#endif

/*********************
*      INCLUDES
*********************/
#ifdef LV_CONF_INCLUDE_SIMPLE
#include "lvgl.h"
#include "lv_watch_conf.h"
#else
#include "../../../lvgl/lvgl.h"
#include "../../../lv_watch_conf.h"
#endif

#if USE_LV_WATCH_EXERCISE_RECORD != 0

#include "lv_watch.h"

#if USE_LV_WATCH_EXERCISE != 0
#include "../exercise/exercise_sport_test.h"
#endif

/*********************
*      DEFINES
*********************/
#ifndef EXERCISE_TEST_MODE
#define EXERCISE_TEST_MODE                         (0)
#endif

#if EXERCISE_TEST_MODE != 0
#define EXERCISE_RECORD_VO2MAX_ZONE_NUM            (EXERCISE_TEST_VO2MAX_ZONE_NUM)
#define EXERCISE_RECORD_HR_ZONE_NUM                (EXERCISE_TEST_HR_ZONE_NUM)
#define EXERCISE_RECORD_CURVE_NODE_NUM             (EXERCISE_TEST_CURVE_NODE_NUM)
#else
#define EXERCISE_RECORD_VO2MAX_ZONE_NUM            (7)
#define EXERCISE_RECORD_HR_ZONE_NUM                (5)
#define EXERCISE_RECORD_CURVE_NODE_NUM             (240)
#endif

/**********************
*      MACROS
**********************/

/**********************
*      TYPEDEFS
**********************/
enum {
    EXERCISE_RECORD_ITEM_TYPE_SPEED = 0,     // top and average speed,average pace
    EXERCISE_RECORD_ITEM_TYPE_PACE,          // top pace, average speed and pace
    EXERCISE_RECORD_ITEM_TYPE_STEP,          // step number,average frequency and stride
    EXERCISE_RECORD_ITEM_TYPE_HEIGHT,        // cumulative climb or decline height,highest altitude
    EXERCISE_RECORD_ITEM_TYPE_HR_CURVE,
    EXERCISE_RECORD_ITEM_TYPE_HR_ZONE,
    EXERCISE_RECORD_ITEM_TYPE_SPEED_CURVE,
    EXERCISE_RECORD_ITEM_TYPE_PACE_CURVE,
    EXERCISE_RECORD_ITEM_TYPE_STRIDE_FREQ_CURVE,
    EXERCISE_RECORD_ITEM_TYPE_ALTITUDE_CURVE,
    EXERCISE_RECORD_ITEM_TYPE_TRAINING_EFFECT,
    EXERCISE_RECORD_ITEM_TYPE_RECOVERY_TIME,
    EXERCISE_RECORD_ITEM_TYPE_VO2MAX,
    EXERCISE_RECORD_ITEM_TYPE_MAX,
};
typedef uint8_t EXERCISE_RECORD_ITEM_TYPE_T;

typedef struct {
    uint8_t sport_type;                                     // EXERCISE_TYPE_T
    uint8_t padding;                                        // unused
    uint16_t bitmap;                                        // 1 << EXERCISE_RECORD_ITEM_TYPE_T
    uint32_t end_time;                                      // in seconds
} exercise_record_base_t;

typedef struct {
    uint32_t total_disctance;                               // in meters
    uint32_t sport_time;                                    // in seconds
    uint32_t calorie;                                       // in kcal
} exercise_record_synthesis_t;

typedef struct {
    uint32_t top_speed;                                     // in meters / hour
    uint32_t aver_speed;                                    // in meters / hour
    uint32_t aver_pace;                                     // in seconds / km
} exercise_record_speed_t;

typedef struct {
    uint32_t top_pace;                                      // in seconds / km
    uint32_t aver_speed;                                    // in meters / hour
    uint32_t aver_pace;                                     // in seconds / km
} exercise_record_pace_t;

typedef struct {
    uint32_t step_number;
    uint32_t aver_stride_freq;                              // in steps / min
    uint32_t aver_stride;                                   // in CM
} exercise_record_step_t;

typedef struct {
    uint32_t climb_height;                                  // in meters
    uint32_t decline_height;                                // in meters
    uint32_t highest_altitude;                              // in meters
} exercise_record_height_t;

typedef struct {
    uint8_t max_hr;
    uint8_t min_hr;
    uint8_t aver_hr;
    uint8_t padding;                                        // unused
    uint8_t hr[EXERCISE_RECORD_CURVE_NODE_NUM];
} exercise_record_hr_curve_t;

typedef struct {
    uint16_t time[EXERCISE_RECORD_HR_ZONE_NUM];             // in minutes
    uint16_t padding;
} exercise_record_hr_zone_t;

typedef struct {
    uint16_t speed[EXERCISE_RECORD_CURVE_NODE_NUM];         // in 10 meters / hour
} exercise_record_speed_curve_t;

typedef struct {
    uint16_t max_pace;                                      // in seconds / km
    uint16_t aver_pace;                                     // in seconds / km
    uint16_t pace[EXERCISE_RECORD_CURVE_NODE_NUM];          // in seconds / km
} exercise_record_pace_curve_t;

typedef struct {
    uint8_t max_freq;
    uint8_t min_freq;
    uint8_t aver_freq;
    uint8_t padding;                                        // unused
    uint8_t freq[EXERCISE_RECORD_CURVE_NODE_NUM];           // in steps / min
} exercise_record_stride_freq_curve_t;

typedef struct {
    uint16_t max_altitude;                                  // in dm
    uint16_t min_altitude;                                  // in dm
    uint16_t aver_altitude;                                 // in dm
    uint16_t padding;                                       // unused
    uint16_t height[EXERCISE_RECORD_CURVE_NODE_NUM];        // in dm
} exercise_record_altitude_curve_t;

typedef struct {
    uint8_t aerobic_training_value;                         // 10 to 50, real value 1.0 to 5.0
    uint8_t anaerobic_training_value;                       // 10 to 50, real value 1.0 to 5.0
    uint16_t padding;                                       // unused
} exercise_record_training_effect_t;

typedef struct {
    uint32_t value;                                         // in seconds
    uint32_t max_value;                                     // in seconds
} exercise_record_recovery_time_t;

typedef struct {
    uint32_t value;                                         // in ml/kg/min
    uint8_t zone[EXERCISE_RECORD_VO2MAX_ZONE_NUM + 1];
} exercise_record_vo2max_t;

typedef struct {
    exercise_record_base_t base;                            // mandatory
    exercise_record_synthesis_t synthesis;                  // mandatory
    exercise_record_speed_t speed;                          // optional,depend on bitmap
    exercise_record_pace_t pace;                            // optional,depend on bitmap
    exercise_record_step_t step;                            // optional,depend on bitmap
    exercise_record_height_t height;                        // optional,depend on bitmap
    exercise_record_hr_curve_t hr_curve;                    // optional,depend on bitmap
    exercise_record_hr_zone_t hr_zone;                      // optional,depend on bitmap
    exercise_record_speed_curve_t speed_curve;              // optional,depend on bitmap
    exercise_record_pace_curve_t pace_curve;                // optional,depend on bitmap
    exercise_record_stride_freq_curve_t stride_freq_curve;  // optional,depend on bitmap
    exercise_record_altitude_curve_t altitude_curve;        // optional,depend on bitmap
    exercise_record_training_effect_t training_effect;      // optional,depend on bitmap
    exercise_record_recovery_time_t recovery_time;          // optional,depend on bitmap
    exercise_record_vo2max_t vo2max;                        // optional,depend on bitmap
} exercise_record_t;

/**********************
* GLOBAL PROTOTYPES
**********************/
void exercise_record_create_event_cb(lv_obj_t * btn, lv_event_t event);
void exercise_record_sport_data_ind(exercise_record_t * record);

#endif /*USE_LV_WATCH_EXERCISE_RECORD*/

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*EXERCISE_RECORD_H*/
